<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

  <title>04.jQuery Plugins</title>
  <link rel="stylesheet" href="../_assets/theme.css">
</head>
<body>
  <!-- Layout will be inserted here. -->
  <div class="main"></div>

  <!-- Layout template. -->
  <script class="layout" type="template" id="layout">
    <h1>Hello</h1>
    <p></p>
  </script>

  <!-- Content template. -->
  <script class="template" type="template" id="content">
    <span></span>
  </script>

  <!-- Sub Content template. -->
  <script class="template" type="template" id="sub-content">
    <span>I'm sub-content!</span>
  </script>

  <!-- Dependencies. -->
  <script src="../../bower_components/jquery/dist/jquery.js"></script>
  <script src="../../bower_components/underscore/underscore.js"></script>
  <script src="../../bower_components/backbone/backbone.js"></script>

  <!-- LayoutManager library. -->
  <script src="../../backbone.layoutmanager.js"></script>

  <!-- Example code. -->
  <script contenteditable="true">
    // Setting this option augments `Backbone.View` to work like `Layout`.
    Backbone.Layout.configure({ manage: true });

    // This will be inserted into both Layouts.
    var ContentView = Backbone.View.extend({
      template: "#content",

      // Initialize your jQuery plugins here.
      afterRender: function() {
        console.log("Content width: " + $(this.el).width());
      }
    });

    var SubContentView = Backbone.View.extend({
      template: "#sub-content",

      afterRender: function() {
        console.log("Sub-content width: " + $(this.el).width());
      }
    });

    // Create a new Layout with a sub view for content.
    var layout = new Backbone.Layout({
      template: "#layout",

      // This will place the contents of the ContentView into the Layout's
      // `<p>`.
      views: {
        p: new ContentView({
          views: {
            span: new SubContentView()
          }
        })
      }
    });

    // Attach the Layout to the main container.
    layout.$el.appendTo(".main");

    // Initially render the Layout.
    layout.render();
  </script>

  <h3><a href="05.No_Template.html">Next example: No Template.</a></h3>
</body>
</html>
